package demoMod.nanaki.utils;

import com.badlogic.gdx.Gdx;
import com.megacrit.cardcrawl.actions.AbstractGameAction;

public class GetWaitAction {
    public static AbstractGameAction get(float dur) {
        return doAndWait(() -> {}, dur);
    }

    public static AbstractGameAction doAndWait(Runnable action, float dur) {
        return new AbstractGameAction() {
            private float t = dur;

            @Override
            public void update() {
                if (t == dur) {
                    action.run();
                }
                t -= Gdx.graphics.getDeltaTime();
                isDone = t < 0;
            }
        };
    }

    public static AbstractGameAction waitAndDo(Runnable action, float dur) {
        return new AbstractGameAction() {
            private float t = dur;

            @Override
            public void update() {
                t -= Gdx.graphics.getDeltaTime();
                isDone = t < 0;
                if (isDone) {
                    action.run();
                }
            }
        };
    }
}
